package com.alibaba.algo.components.permission.controller;

import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.algo.components.permission.auth.CheckAuth;
import com.alibaba.algo.components.permission.auth.enums.AuthMethod;
import com.alibaba.algo.components.permission.auth.enums.AuthParam;
import com.alibaba.algo.components.permission.auth.enums.AuthScheme;
import com.alibaba.algo.components.permission.vo.LoginVO;
import com.alibaba.algo.core.resp.BaseResult;
import com.alibaba.fastjson.JSON;

import lombok.extern.slf4j.Slf4j;

/**
 * @Description: 授权自定义注解测试类
 * @author: malin
 * @date: 2020-12-16 10:08:29
 */
@Slf4j
@RestController
@RequestMapping(value = "/test/")
public class AuthTestController {

	@CheckAuth(method = AuthMethod.POST, scheme = AuthScheme.HTTP, param = { AuthParam.ACCESS_TOKEN, AuthParam.SIGN,AuthParam.NONCE })
	@PostMapping("/demo")
	public BaseResult demo(@RequestBody LoginVO loginVO, HttpServletRequest request) {
		log.info("param:{}", JSON.toJSONString(loginVO));
		for (Enumeration<String> paramNames = request.getHeaderNames(); paramNames.hasMoreElements();) {
			String paramName = paramNames.nextElement();
			System.err.println(paramName + ":" + request.getHeader(paramName));
		}
		return BaseResult.buildSuccess();
	}
}
